//检测是否开启无障碍服务
auto.waitFor()
toast("芜湖，起飞ʘᴗʘ");
launchApp("抖音极速版");
//设置悬浮窗方便快速退出
w = floaty.rawWindow(
    <vertical>
        <horizontal>
            <button id="esc" text="esc"/>
        </horizontal>
    </vertical>
);
w.setTouchable(true); //悬浮窗可触摸
w.esc.on("click", () => {
    home();
    exit();
})
className("android.widget.RelativeLayout").clickable(true).depth(9).findOne().click()
className("android.view.View").clickable(true).checked(false).indexInParent(3).depth(12).findOne(1000).click()
if (className("android.view.View").clickable(true).checked(false).indexInParent(3).depth(16).findOne(1000)) {
    className("android.view.View").clickable(true).checked(false).indexInParent(3).depth(16).findOne(1000).click()
}
//刷日常任务
if (className("android.view.View").text("逛街赚钱").findOne(8000)) {
    className("android.view.View").text("逛街赚钱").findOne(8000).parent().parent().parent().click();
    if (text("浏览商品得金币").findOne(3000)) {
        if (className("android.view.View").text("明日浏览可领取奖励").findOne(3000) || text("已领取").findOne(3000)) {
            back();
            sleep(2000);
        } else {
            for (i = 0; i < 4; i++) {
                sleep(6500);
                gesture(1000, [500, 1200], [500, 800]);
            }
            sleep(2000);
            back();
            sleep(1000);
        }
    }
}
gesture(1000, [500, device.height - 100], [500, 100]);
sleep(2000);
if (className("android.view.View").text("走路赚金币").findOne(8000)) {
    toast("走路赚金币");
    className("android.view.View").text("走路赚金币").findOne(400).parent().parent().click()
    sleep(1000);
    press(device.width / 2, device.height * 2 / 5, 300);
    sleep(1000)
    back();
}
if (className("android.view.View").text("吃饭补贴").findOne(8000)) {
    toast("吃饭补贴");
    className("android.view.View").text("吃饭补贴").findOne(8000).parent().parent().click();
    sleep(2000);
    press(device.width / 2, device.height * 6 / 7, 300);
    sleep(1000);
    back();
    sleep(1000);
}
if (className("android.view.View").text("看小说").findOne(8000)) {
    className("android.view.View").text("看小说").findOne(8000).parent().parent().click();
    className("android.view.View").clickable(true).checked(false).indexInParent(6).depth(15).findOne().click()
    className("android.view.View").column(0).clickable(true).checked(false).indexInParent(0).depth(16).findOne().click()
    sleep(2000)
    for (i = 0; i < 100; i++) {
        gesture(1000, [device.width - 100, 800], [100, 800]);
        sleep(500);
    }
    back();
    sleep(1000);
    if (text("确认").findOne(1000)) {
        text("确认").findOne().click();
    }
    sleep(500);
    back();
    className("android.view.View").clickable(true).checked(false).indexInParent(7).depth(15).findOne().click()
    className("android.view.View").column(0).clickable(true).checked(false).indexInParent(0).depth(16).findOne().click()
    sleep(2000)
    for (i = 0; i < 100; i++) {
        gesture(1000, [device.width - 100, 800], [100, 800]);
        sleep(500);
    }
    back();
    sleep(1000);
    if (text("确认").findOne(1000)) {
        text("确认").findOne().click();
    }
    sleep(500);
    back();
    sleep(500);
    back();
    sleep(1000);
}
if (id("u8").findOne(3000)) {
    id("u8").findOne(3000).click();
} else {
    back();
}
//刷视频
for (i = 0; i < 600; i++) {
    sleep(5000);
    gesture(1000, [500, device.height / 2], [500, 100]);
    sleep(6000);
    gesture(1000, [500, device.height / 2], [500, 100]);
    sleep(7000);
    gesture(1000, [500, device.height / 2], [500, 100]);
}
events.onKeyDown("volume_down", function(event) {
    toast("菜单键被按下了");
    exit();
});